package com.xiaobai.netease_news.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Android Studio
 * Project: NeteaseNews
 * Author: Jack
 * Email: jackfangqi1314@gmail.com/jackfangqi@163.com
 * Date: 2015/6/7
 */
public class ReadRecommendData {
    private String tags;
    private String tag;
    private String boardid;
    private String digest;
    private String docid;
    private int downTimes;
    private String id;
    private String img;
    private String imgsrc;
    private int picCount;
    private String pixel;
    private String prompt;
    private int replyCount;
    private String replyId;
    private String source;
    private String template;
    private String tid;
    private String title;
    private int upTimes;
    private List<ImgNewExtra> imgNewExtras;
    private String ptime;

    public String getTags() {
        return tags;
    }

    public String getTag() {
        return tag;
    }

    public String getBoardid() {
        return boardid;
    }

    public String getDigest() {
        return digest;
    }

    public String getDocid() {
        return docid;
    }

    public int getDownTimes() {
        return downTimes;
    }

    public String getId() {
        return id;
    }

    public String getImg() {
        return img;
    }

    public String getImgsrc() {
        return imgsrc;
    }

    public int getPicCount() {
        return picCount;
    }

    public String getPixel() {
        return pixel;
    }

    public String getPrompt() {
        return prompt;
    }

    public int getReplyCount() {
        return replyCount;
    }

    public String getReplyId() {
        return replyId;
    }

    public String getSource() {
        return source;
    }

    public String getTemplate() {
        return template;
    }

    public String getTid() {
        return tid;
    }

    public String getTitle() {
        return title;
    }

    public int getUpTimes() {
        return upTimes;
    }

    public List<ImgNewExtra> getImgNewExtras() {
        return imgNewExtras;
    }

    public String getPtime() {
        return ptime;
    }

    public void parseJson(JSONObject jsonObject) {
        if (jsonObject != null) {
            tags = jsonObject.optString("TAGS");
            tag = jsonObject.optString("TAG");
            boardid = jsonObject.optString("boardid");
            digest = jsonObject.optString("digest");
            docid = jsonObject.optString("docid");
            downTimes = jsonObject.optInt("downTimes");
            id = jsonObject.optString("id");
            img = jsonObject.optString("img");
            imgsrc = jsonObject.optString("imgsrc", null);
            picCount = jsonObject.optInt("picCount");
            pixel = jsonObject.optString("pixel");
            prompt = jsonObject.optString("prompt");
            replyCount = jsonObject.optInt("replyCount");
            replyId = jsonObject.optString("replyid");
            source = jsonObject.optString("source");
            template = jsonObject.optString("template");
            tid = jsonObject.optString("tid");
            title = jsonObject.optString("title");
            upTimes = jsonObject.optInt("upTimes");
            ptime = jsonObject.optString("ptime");

            JSONArray array = jsonObject.optJSONArray("imgnewextra");
            if (array != null) {
                imgNewExtras = new ArrayList<>();
                int length = array.length();
                for (int i = 0; i < length; i++) {
                    try {
                        JSONObject object = array.getJSONObject(i);
                        ImgNewExtra imgNewExtra = new ImgNewExtra();
                        imgNewExtra.parseJson(object);

                        imgNewExtras.add(imgNewExtra);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
